// Townscript for town 5: Voughton

begintownscript;

variables;

int c,choice,day6;
short amount_to_withdraw;
short amount_to_pay;
short which_state;
short what_num;

body;

beginstate INIT_STATE;

	set_name(6,"Mayor Ruth");
	set_name(7,"Jordan");
	set_name(35,"Benthol");
	set_name(46,"Pete");
	set_name(8,"Just-married man");
	set_name(9,"Just-married women");
	set_name(10,"Cornelia");
	set_name(11,"Monard");
	set_name(12,"Wellroy");
	set_name(14,"Benthol");
	set_name(13,"Mother Sofia");
	set_name(40,"Boris");
	set_name(70,"Empire HQ leader");
	
	set_crime_tolerance(3);

break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;

	if (get_flag(17,5) == 1)
			activate_hidden_group(14); // official of HQ present
	
	if (get_flag(17,5) == 1) {
			day6 = get_flag(250,7);
	
			if (what_day_of_scenario() >= day6 + 3) {
					set_flag(17,5,2);
					}
			}
	
	if (get_flag(17,5) == 2)
			erase_char(70); // official of HQ has left

	if (get_flag(5,2) > 0) // after killing bandit leader, Empire liaison will not reappear
			erase_char(7);

	if (get_flag(6,1) == 0) { // Empire Liaison kidnapped if bandit leader not dead
			if (get_flag(5,2) == 0) {
					if (what_day_of_scenario() > 2) {
							set_flag(5,2,1);
							erase_char(7);
							}
					}
			}
	
	if (get_flag(200,1) == 1) {
			if (get_flag(5,21) == 1) {
					message_dialog("You enter Voughton after the disaster at the Empire HQ. The number of town guards has been expanded somewhat, which is logical. You hope Thralni will not manage to attack before you get to him.","");
					set_flag(5,21,1);
					}
				activate_hidden_group(9);
				}

	if (get_flag(200,1) == 1) {
			activate_hidden_group(9); // activate guards
			erase_char(42); // erase characters
			erase_char(43);
			erase_char(44);
			erase_char(45);
			erase_char(46);
			erase_char(47);
			erase_char(36);
			erase_char(37);
			erase_char(38);
			erase_char(39);
			set_terrain(5,32,0); // erasing tradesmen carriges
			set_terrain(5,31,0);
			set_terrain(5,29,0);
			set_terrain(5,28,0);
			set_terrain(5,26,0);
			set_terrain(5,25,0);
			set_terrain(34,5,223); // adding filth to lodge
			set_terrain(35,3,224);
			set_terrain(38,5,223);
			set_terrain(41,5,224);
			set_flag(5,26,1); // Triggers message nodes
			}
	
	if (get_flag(200,1) == 1) {
			if (get_flag(5,28) == 0) {
					message_dialog("Voughton is very empty now. That is, it is filled with guards, but all normal townsfolk are not to be seen on the streets. Even some of the gates had to be closed, as you can see when looking behind you.","The recent course of events is very bad for the province. Something has to be done.");
					set_flag(5,28,1);
					}
			}
			

	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(6,"Are you bored?");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(6,"I've a quest for you.");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(6,"Goddamn thugs");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(7,"I'm the Empire Liaison");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(7,"Irritating Thralni");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(7,"Hmmm");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(35,"Zzzzzz");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(14,"Nice swords");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(14,"All for charity");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(14,"I get the money");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(10,"How about the white one?");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(10,"Or maybe the pink dress?");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(8,"I can't decide");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(8,"How about the white?");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(9,"I like the pink");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(9,"Shall we buy the pink?");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(11,"Scribble scribble");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(11,"How do you spell that?");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(11,"Hmmmm");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(12,"Nice bread");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(12,"Nice fish");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(12,"Nice greens");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(13,"*Wipe*");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(13,"The altar should be clean");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(39,"Nice cheap rooms");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(39,"Without breakfast");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(49,"Zzzzz");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(49,"Snore");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(48,"Meow");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(45,"Meow");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(47,"Meow");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(40,"Get a drink");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(40,"A nice room for ye' folks!");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(44,"Sigh");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(43,"I disagree");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(43,"You're wrong");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(43,"No, that's not true");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(42,"No, you're wrong");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(42,"That really isn't true!");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(42,"You're talking nonsense!");

break;

beginstate 10;
reset_dialog();
add_dialog_str(0,"You find a trapdoor. When you open it a little, you see a wooden ladder leading down. Do you want to climb down?",0);
add_dialog_choice(0,"Climb down");
add_dialog_choice(1,"Leave");
choice = run_dialog(0);

	if (choice == 1)
			move_to_new_town(6,35,43);
break;

beginstate 11;
// state no longer used
break;

beginstate 12;
// State no longer used
break;

beginstate 13;
// State no longer used
break;

beginstate 14;

// This state is no longer used

break;

beginstate 15;
reset_dialog();
add_dialog_str(0,"This control panel has a small screen and some buttons next to it. It's not very large. On the screen, a small message is displayed:",0);
add_dialog_str(1,"_Welcome to Banka Riverrod. What would you like to do?_ Two options are listed below. The third one isn't on the screen, it is there to give you the option not to do anything.",0);
add_dialog_choice(0,"Withdraw");
add_dialog_choice(1,"Deposit");
add_dialog_choice(2,"Do nothing");
choice = run_dialog(0);
	
	if (choice == 1) {
			c = coins_amount();
			print_num(c);
			
			message_dialog("Down in the text area you can see how many coins you have. It says _debug value,_ followed by your amount of coins. Just pretend it says _amount of coins,_ will you?","Click OK to proceed, please.");
			message_dialog("In the next dialog box you'll have to define an mount of money. DON'T ask for more than 100 coins per time!","Click OK to proceed, please.");
			
			get_text_response("Enter an amount to withdraw, please.");
			
			which_state = 19;
			set_state_continue(18);
			}
	
	if (choice == 2) {
			c = coins_amount();
			print_num(c);
			
			message_dialog("Down in the text area you can see how many coins you have. It says _debug value,_ followed by your amount of coins. Just pretend it says _amount of coins,_ will you?","Click OK to proceed, please.");
			message_dialog("In the next dialog box you'll have to define an mount of money. DON'T ask for more than 100 coins per time!","Click OK to proceed, please.");
			
			get_text_response("Enter an amount to deposit, please.");
			
			which_state = 20;
			set_state_continue(18);
			}
break;


beginstate 16;
	message_dialog("You tell her everything you know and saw, and what you exactly did. _Indeed, we thought it was just some earthquake,_ she says, when you tell her of the reactor explosion.","_You must find out who did this. He won't get away with this!_ She stands up and asks for a guard to see you to the exit. When you leave the room, she says: _Find him!_");
break;

beginstate 17;
if (get_flag(5,5) == 1)
		end();
	message_dialog("This bridge looks old. Four arches let the water stream under the bridge. Its a nice bridge, but it could use some paint.","");
	set_flag(5,5,1);
break;

beginstate 18;
what_num = 0;

	check_text_response_match("1");
	if (got_text_match())
		what_num = 1;
	check_text_response_match("2");
	if (got_text_match())
		what_num = 2;
	check_text_response_match("3");
	if (got_text_match())
		what_num = 3;
	check_text_response_match("4");
	if (got_text_match())
		what_num = 4;
	check_text_response_match("5");
	if (got_text_match())
		what_num = 5;
	check_text_response_match("6");
	if (got_text_match())
		what_num = 6;
	check_text_response_match("7");
	if (got_text_match())
		what_num = 7;
	check_text_response_match("8");
	if (got_text_match())
		what_num = 8;
	check_text_response_match("9");
	if (got_text_match())
		what_num = 9;
	check_text_response_match("10");
	if (got_text_match())
		what_num = 10;
	check_text_response_match("11");
	if (got_text_match())
		what_num = 11;
	check_text_response_match("12");
	if (got_text_match())
		what_num = 12;
	check_text_response_match("13");
	if (got_text_match())
		what_num = 13;
	check_text_response_match("14");
	if (got_text_match())
		what_num = 14;
	check_text_response_match("15");
	if (got_text_match())
		what_num = 15;
	check_text_response_match("16");
	if (got_text_match())
		what_num = 16;
	check_text_response_match("17");
	if (got_text_match())
		what_num = 17;
	check_text_response_match("18");
	if (got_text_match())
		what_num = 18;
	check_text_response_match("19");
	if (got_text_match())
		what_num = 19;
	check_text_response_match("20");
	if (got_text_match())
		what_num = 20;
	check_text_response_match("21");
	if (got_text_match())
		what_num = 21;
	check_text_response_match("22");
	if (got_text_match())
		what_num = 22;
	check_text_response_match("23");
	if (got_text_match())
		what_num = 23;
	check_text_response_match("24");
	if (got_text_match())
		what_num = 24;
	check_text_response_match("25");
	if (got_text_match())
		what_num = 25;
	check_text_response_match("26");
	if (got_text_match())
		what_num = 26;
	check_text_response_match("27");
	if (got_text_match())
		what_num = 27;
	check_text_response_match("28");
	if (got_text_match())
		what_num = 28;
	check_text_response_match("29");
	if (got_text_match())
		what_num = 29;
	check_text_response_match("30");
	if (got_text_match())
		what_num = 30;
	check_text_response_match("31");
	if (got_text_match())
		what_num = 31;
	check_text_response_match("32");
	if (got_text_match())
		what_num = 32;
	check_text_response_match("33");
	if (got_text_match())
		what_num = 33;
	check_text_response_match("34");
	if (got_text_match())
		what_num = 34;
	check_text_response_match("35");
	if (got_text_match())
		what_num = 35;
	check_text_response_match("36");
	if (got_text_match())
		what_num = 36;
	check_text_response_match("37");
	if (got_text_match())
		what_num = 37;
	check_text_response_match("38");
	if (got_text_match())
		what_num = 38;
	check_text_response_match("39");
	if (got_text_match())
		what_num = 39;
	check_text_response_match("40");
	if (got_text_match())
		what_num = 40;
	check_text_response_match("41");
	if (got_text_match())
		what_num = 41;
	check_text_response_match("42");
	if (got_text_match())
		what_num = 42;
	check_text_response_match("43");
	if (got_text_match())
		what_num = 43;
	check_text_response_match("44");
	if (got_text_match())
		what_num = 44;
	check_text_response_match("45");
	if (got_text_match())
		what_num = 45;
	check_text_response_match("46");
	if (got_text_match())
		what_num = 46;
	check_text_response_match("47");
	if (got_text_match())
		what_num = 47;
	check_text_response_match("48");
	if (got_text_match())
		what_num = 48;
	check_text_response_match("49");
	if (got_text_match())
		what_num = 49;
	check_text_response_match("50");
	if (got_text_match())
		what_num = 50;
	check_text_response_match("51");
	if (got_text_match())
		what_num = 51;
	check_text_response_match("52");
	if (got_text_match())
		what_num = 52;
	check_text_response_match("53");
	if (got_text_match())
		what_num = 53;
	check_text_response_match("54");
	if (got_text_match())
		what_num = 54;
	check_text_response_match("55");
	if (got_text_match())
		what_num = 55;
	check_text_response_match("56");
	if (got_text_match())
		what_num = 56;
	check_text_response_match("57");
	if (got_text_match())
		what_num = 57;
	check_text_response_match("58");
	if (got_text_match())
		what_num = 58;
	check_text_response_match("59");
	if (got_text_match())
		what_num = 59;
	check_text_response_match("60");
	if (got_text_match())
		what_num = 60;
	check_text_response_match("61");
	if (got_text_match())
		what_num = 61;
	check_text_response_match("62");
	if (got_text_match())
		what_num = 62;
	check_text_response_match("63");
	if (got_text_match())
		what_num = 63;
	check_text_response_match("64");
	if (got_text_match())
		what_num = 64;
	check_text_response_match("65");
	if (got_text_match())
		what_num = 65;
	check_text_response_match("66");
	if (got_text_match())
		what_num = 66;
	check_text_response_match("67");
	if (got_text_match())
		what_num = 67;
	check_text_response_match("68");
	if (got_text_match())
		what_num = 68;
	check_text_response_match("69");
	if (got_text_match())
		what_num = 69;
	check_text_response_match("70");
	if (got_text_match())
		what_num = 70;
	check_text_response_match("71");
	if (got_text_match())
		what_num = 71;
	check_text_response_match("72");
	if (got_text_match())
		what_num = 72;
	check_text_response_match("73");
	if (got_text_match())
		what_num = 73;
	check_text_response_match("74");
	if (got_text_match())
		what_num = 74;
	check_text_response_match("75");
	if (got_text_match())
		what_num = 75;
	check_text_response_match("76");
	if (got_text_match())
		what_num = 76;
	check_text_response_match("77");
	if (got_text_match())
		what_num = 77;
	check_text_response_match("78");
	if (got_text_match())
		what_num = 78;
	check_text_response_match("79");
	if (got_text_match())
		what_num = 79;
	check_text_response_match("80");
	if (got_text_match())
		what_num = 80;
	check_text_response_match("81");
	if (got_text_match())
		what_num = 81;
	check_text_response_match("82");
	if (got_text_match())
		what_num = 82;
	check_text_response_match("83");
	if (got_text_match())
		what_num = 83;
	check_text_response_match("84");
	if (got_text_match())
		what_num = 84;
	check_text_response_match("85");
	if (got_text_match())
		what_num = 85;
	check_text_response_match("86");
	if (got_text_match())
		what_num = 86;
	check_text_response_match("87");
	if (got_text_match())
		what_num = 87;
	check_text_response_match("88");
	if (got_text_match())
		what_num = 88;
	check_text_response_match("89");
	if (got_text_match())
		what_num = 89;
	check_text_response_match("90");
	if (got_text_match())
		what_num = 90;
	check_text_response_match("91");
	if (got_text_match())
		what_num = 91;
	check_text_response_match("92");
	if (got_text_match())
		what_num = 92;
	check_text_response_match("93");
	if (got_text_match())
		what_num = 93;
	check_text_response_match("94");
	if (got_text_match())
		what_num = 94;
	check_text_response_match("95");
	if (got_text_match())
		what_num = 95;
	check_text_response_match("96");
	if (got_text_match())
		what_num = 96;
	check_text_response_match("97");
	if (got_text_match())
		what_num = 97;
	check_text_response_match("98");
	if (got_text_match())
		what_num = 98;
	check_text_response_match("99");
	if (got_text_match())
		what_num = 99;
	check_text_response_match("100");
	if (got_text_match())
		what_num = 100;
		
	// Make sure the player actually entered something correct. If not, end.
	
	if (what_num == 0)
		{message_dialog("A light flickers above the screen, saying the following:","_That wasn't a value between 1 and 100. Transaction cancelled._");
		end();
		}

	set_state_continue(which_state);
break;

beginstate 19;
			amount_to_withdraw = what_num;
			
			if (get_flag(50,0) >= amount_to_withdraw) {
					change_coins(amount_to_withdraw);
					
					inc_flag(50,0,(what_num - (2 * what_num)));
					
					message_dialog("A small drawer appears, filled with money. You take the money out, and it closes.","");
					
					message_dialog("_You have withdrawn an amount of money. Thanks for coming to the Banka Riverrod._","Your new amount of money is shown at the bottom of the playing screen.");
				
					c = coins_amount();
					print_num(c);
					end();
					}
			
			if (get_flag(50,0) < amount_to_withdraw) {
					message_dialog("You don't have such a big sum of money in your bank account. Transaction cancelled.","");
					end();
					}
break;

beginstate 20;
			amount_to_pay = (what_num - (2 * what_num));
			
			if (coins_amount() >= amount_to_pay) {
					change_coins(amount_to_pay);
					
					inc_flag(50,0,what_num);
					
					message_dialog("A small drawer appears, in which you put your money. It closes.","");
					
					message_dialog("_You have deposited an amount of money. Thanks for coming to the Banka Riverrod._","Your new amount of money is shown at the bottom of the playing screen.");
					
					c = coins_amount();
					print_num(c);
					
					end();
					}
			
			if (c < amount_to_pay) {
					message_dialog("A small drawer opens, in which you put your money. It closes. However, it opens almost immediately. You look at the red flashing screen:","That is not the right sum. Transaction cancelled.");
					end();
					}
break;

beginstate 21;
if (get_flag(5,26) == 1) {
	if (get_flag(5,27) == 1)
			end();
		message_dialog("Once this would have been a nice, small lodge.","Now its covered with filth. The owner left Voughton as a reaction to the attack on the Empire headquarters.");
		set_flag(5,27,1);
		}
break;